<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>公告管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        var callback = function () {
            grid.reload();
        };
        $(function () {
            $("#endTime").ligerDateEditor();
            $("#beginTime").ligerDateEditor();
            initForm();
            initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
            searchBtnEvent();
            clearBtnEvent();
        });

        //清空按钮事件
        function clearBtnEvent() {
            $("#clearBtn").click(function (event) {
                clearLigerForm("searchBar");
            });
        }

        //初始化表单
        function initForm() {
            $("#searchBar").ligerForm();
        }

        //查询按钮事件
        function searchBtnEvent() {
            $("#searchBtn").click(function (event) {
                var beginTime=$("#beginTime").val();
                var endTime=$("#endTime").val();
                if(beginTime==""){
                    if(endTime!=""){
                        alert("开始时间不能为空！");
                        return;
                    }
                }else{
                    if(endTime==""){
                        alert("结束时间不能为空！");
                        return;
                    }
                }
                if(beginTime!=""&&endTime!=""){
                    if(endTime<beginTime){
                        alert("开始时间不得大于结束时间！");
                        return;
                    }
                }
                var form = new liger.get("searchBar");
                var data = form.getData();
                for (name in data) {
                    grid.setParm(name, data[name]);
                }
                ;
                grid.reload();
            });
        }

        //初始化列表
        function initGrid() {
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/carloan/odrnoticeinfo/initList.do',
                method: 'get',
                columns: [
                    {display: '标题', name: 'title', width: 400, enabledSort: true},
                    {display: '时间', name: 'mdfTm', width: 400, render: renderDate, enabledSort: true},
                    {
                        display: '操作', width: 400,
                        render: function (rowdata, rowindex, value) {
                            var h1 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="modifycmsbnrdc(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>'
                            var h2 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="isTop(' + rowdata.id + ')"><i class="sqBtnIco_12"></i>置顶</a>';
                            var h3 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="isDel(' + rowdata.id + ')"><i class="sqBtnIco_13"></i>删除</a>';
                            var h4 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="outExcel(' + rowdata.id + ')"><i class="sqBtnIco_13"></i>导出</a>';
                            return h1 + h2 + h3;
                        }
                    }
                ],
                pageSize: 10,
                root: 'rows',
                record: 'total',
                rownumbers: true,
                hideLoadButton: true,
                width: '100%',
                height: '100%',
                heightDiff: -2,
                fixedCellHeight: false
            });
            grid = liger.get("ligergrid1");
            grid.setHeight(100);
        }

        //格式化时间
        function renderDate(rowdata, index, value) {
            var dateStr = "";
            if (null != value) {
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
            }
            return dateStr;
        }

        //修改
        function modifycmsbnrdc(id) {
            var tit = '新增公告';
            var tabid = 'AddCmsBnrDc';
            if (id != '') {
                tit = '修改公告';
                tabid = 'ModifyCmsBnrDc' + id;
            }
            Add_navTab(tabid, tit, '<%=path%>/carloan/odrnoticeinfo/toModifyPage.do?id=' + id, callback);
        }

        //是否置顶
        function isTop(id) {
            var stsstr = "确认置顶";
            $.ligerDialog.confirm(stsstr, function (flag) {
                if (flag == false) return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {noticeId: JSON.stringify(id), isTop: 1},
                    url: '<%=path%>/carloan/odrnoticeinfo/modify.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        function isDel(id) {
            var stsstr = "确认删除";
            $.ligerDialog.confirm(stsstr, function (flag) {
                if (flag == false) return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {noticeId: JSON.stringify(id), isDel: 1},
                    url: '<%=path%>/carloan/odrnoticeinfo/modify.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        function outExcel(id) {
            var stsstr = "确认导出";
            $.ligerDialog.confirm(stsstr, function (flag) {
                if (flag == false) return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {noticeId: JSON.stringify(id)},
                    url: '<%=path%>/carloan/odrnoticeinfo/outExcel.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }

    </script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33"  isyw="0">
                        <div class="label">开始时间</div>
                        <div class="field">
                            <input name="beginTime" id="beginTime" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33"  isyw="0">
                        <div class="label">结束时间</div>
                        <div class="field">
                            <input name="endTime" id="endTime" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                <div class="fieldBox col_33">
                    <div class="label">公告标题</div>
                    <div class="field">
                        <input name="title" id="title" type="text" class="ui-textbox" value="">
                    </div>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
                <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                <span id="addBtn" class="sq-button sq-button-hasicon" onclick="modifycmsbnrdc('')"><i
                        class="sqBtnIco_3"></i>新增</span>
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </form>
    </div>
    <input type="hidden" id="textContent" name="textContect">
    <div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>